from selenium import webdriver

# 选择浏览器
# from selenium.webdriver.chrome.service import Service


class UseBrowser:
    driver = None

    def __init__(self, browser_name='chrome', path='../../chromedriver.exe'):
        try:
            if browser_name.lower() == 'chrome':  # 把输入转化为小写
                options = webdriver.ChromeOptions()
                options.add_experimental_option("excludeSwitches", ["enable-automation", "enable-logging"])
                # driver_service = Service(executable_path=path)
                self.driver = webdriver.Chrome(executable_path=path, options=options)
                self.driver.maximize_window()
                self.driver.implicitly_wait(3)
                UseBrowser.driver = self.driver

            elif browser_name.lower() == 'firefox':
                self.driver = webdriver.Firefox(path)
                self.driver.maximize_window()
                self.driver.implicitly_wait(3)
                UseBrowser.driver = self.driver


        except Exception as e:
            print('browser init error', e)

    @classmethod
    def browser_quit(cls):
        cls.driver.quit()


if __name__ == '__main__':
    use = UseBrowser()
